/*
 * Copyright 2011 Michele Mancioppi [michele.mancioppi@gmail.com]
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package cave.nice.testMessage.data;

import java.util.Map;

import javax.persistence.Basic;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.ManyToOne;

import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

import cave.nice.testMessage.TestMessageConstants;

import com.google.appengine.api.datastore.Key;

@XmlAccessorType(XmlAccessType.FIELD)
@XmlRootElement
@Entity
public class ReportingPolicy {

	public enum ReportingPolicyType {
		GMail, GTalk
	}

	@XmlTransient
	@Id @GeneratedValue(strategy = GenerationType.IDENTITY)
	private Key identifier;

	// Make the field transient to avoid infinite loops
	@XmlTransient
	@ManyToOne(fetch = FetchType.LAZY)
	private VerifiedAccount account;

	@Basic
	private ReportingPolicyType type;

	@Basic
	private int notifyAfterMinutes = TestMessageConstants.DEFAULT_NOTIFY_AFTER_OVERDUE;

	@Basic
	private boolean notifyIfNoOpenTests = TestMessageConstants.DEFAULT_NOTIFY_IF_NO_OPEN_TESTS;

	@Basic
	private Map<String, String> parameters;

	public Key getIdentifier() {
		return identifier;
	}

	public VerifiedAccount getAccount() {
		return account;
	}

	public void setAccount(VerifiedAccount account) {
		this.account = account;
	}

	public ReportingPolicyType getType() {
		return type;
	}

	public void setType(ReportingPolicyType type) {
		this.type = type;
	}

	public int getNotifyAfterMinutes() {
		return notifyAfterMinutes;
	}

	public void setNotifyAfterMinutes(int notifyAfterMinutes) {
		this.notifyAfterMinutes = notifyAfterMinutes;
	}

	public boolean isNotifyIfNoOpenTests() {
		return notifyIfNoOpenTests;
	}

	public void setNotifyIfNoOpenTests(boolean notifyIfNoOpenTests) {
		this.notifyIfNoOpenTests = notifyIfNoOpenTests;
	}

	public Map<String, String> getParameters() {
		return parameters;
	}

	public void setParameters(Map<String, String> parameters) {
		this.parameters = parameters;
	}

}
